package org.frog.sgs.server.msg;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

import org.frog.sgs.card.basic.Basic;
import org.frog.sgs.card.equipment.Equipment;
import org.frog.sgs.card.scheme.type.JudgeType;
import org.frog.sgs.character.Character;
import org.frog.sgs.event.SgsEventCode;
import org.frog.sgs.io.SgsMsg;

/**
 * @author duanxiangqi
 * @date 2012-10-26
 */
public class ServerMsgSyncCharacterInfo extends SgsMsg {

	private static final long serialVersionUID = -3194850296731511971L;

	public ServerMsgSyncCharacterInfo(Character character) {
		super(SgsEventCode.SYNC_CHARACTER_INFO);
		try {
			writeInt(character.getStrength().getStrength());
			Collection<Basic> cardsInHand = character.getCardsInHand().values();
			writeInt(cardsInHand.size());
			for (Basic basic : cardsInHand) {
				writeInt(basic.getId());
			}
			Map<Integer, Equipment> equipments = character.getEquipments();
			writeInt(equipments.size());
			for (Integer position : character.getEquipments().keySet()) {
				writeInt(position);
				writeInt(character.getEquipments().get(position).getId());
			}
			Map<JudgeType, Basic> judgeSchemes = character.getJudgeSchemes();
			writeInt(judgeSchemes.size());
			for (JudgeType judgeType : judgeSchemes.keySet()) {
				writeInt(judgeType.getValue());
				writeInt(judgeSchemes.get(judgeType).getId());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
